package com.plat.api.action;

import com.alibaba.fastjson.JSONObject;
import com.plat.api.util.RedisUtil;

/**
 * Created with IntelliJ IDEA.
 * User: shish
 * Date: 2020/11/8
 * Time: 17:02
 * Description: No Description
 */
public class The implements Runnable {
   private RedisUtil redisUtil;
    private final String key = "QIANG:";
    public The(RedisUtil redisUtil) {
        this.redisUtil = redisUtil;
    }

    //获取抢购数量
    //获取抢购数量
    public   int getNum(JSONObject body) {
        long count = redisUtil.incrBy(key + body.getString("goodsSn"), -1);
        if (count < 0) {
            //throw new PlatException("客官,来晚了，抢光了");
            System.out.println("客官,来晚了，抢光了");
        }
        return (int) count;
    }

    @Override
    public void run() {
        JSONObject body = new JSONObject();
        body.put("goodsSn","81775980177");
        getNum(body);
    }
}
